﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Betop.Lib.Core.Base;

namespace Betop.Lib.Core.Attach
{
    public class ImageDAL:BaseDAL
    {
        private string _tableName;
        public ImageDAL(string tableName)
        {
            this._tableName = tableName;
        }

        public  List<ImageInfo> GetList(int bindID, string flag)
        {
            string sql = "select * from " + _tableName + " where BindID = @p0";
            if (!string.IsNullOrEmpty(flag))
            {
                sql += " and Flag = " + flag;
            }

            List<ImageInfo> list = dbOper.Query<ImageInfo>(sql, bindID);
            return list;
        }

        public IEnumerable<int> GetIDs(object bindID)
        {
            string sql = "select ID from " + _tableName + " where BindID=@p0";
            List<int> ids = dbOper.Query<int>(sql, bindID);
            return ids;
        }

        public int GetMaxOrder(int bindID)
        {
            string sql = "select isnull(max(Orders) + 1,1) from " + _tableName + " where BindID=@p0";
            int order = dbOper.GetScalar<int>(sql, bindID);
            return order;
        }
    }
}
